package _021_10_4

func duplicateZeros(arr []int) {
	for i := 0; i < len(arr); i++ {
		if arr[i] == 0 {
			for j := len(arr) - 1; j > i; j-- {
				arr[j] = arr[j-1]
			}
			i++
		}
	}

}

func duplicateZeros2(arr []int) {
	zeroNum := 0
	for i := 0; i < len(arr); i++ {
		if arr[i] == 0 {
			zeroNum++
		}
	}
	newData := make([]int, len(arr)+zeroNum)
	j := 0
	for i := 0; i < len(arr); i++ {
		if arr[i] == 0 {
			newData[j] = 0
			newData[j+1] = 0
			j += 2
			continue
		}

		newData[j] = arr[i]
		j++
	}
	copy(arr, newData)
}
